package logic

import (
	"context"
	"fmt"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *srv.GoodAddRequest) (*srv.GoodAddResponse, error) {
	// todo: add your logic here and delete this line

	g := mysql.Good{
		GoodName:  in.GoodName,
		GoodNum:   in.GoodNum,
		GoodPrice: float64(in.GoodPrice),
		GoodStock: in.GoodStock,
		GoodLike:  in.GoodLike,
		GoodAdopt: int(in.GoodAdopt),
	}
	err := g.Create()
	if err != nil {
		return nil, fmt.Errorf("商品添加失败")
	}

	return &srv.GoodAddResponse{Id: int64(g.ID)}, nil
}
